package com.yww.leetcode.deque;

import com.yww.datastructure.deque.ArrayDeque;
import com.yww.datastructure.deque.Deque;
import com.yww.datastructure.deque.LinkedListDeque;

/**
 * @author yww
 * @description 641. 设计循环双端队列
 * @since 2024/2/5 16:12
 */
public class MyCircularDeque641 {
    private Deque<Integer> deque;

    public MyCircularDeque641(int k) {
        if (k % 2 == 0) {
            deque = new LinkedListDeque<>(k);
        } else {
            deque = new ArrayDeque<>(k);
        }
    }

    public boolean insertFront(int value) {
        return deque.offerFirst(value);
    }

    public boolean insertLast(int value) {
        return deque.offerLast(value);
    }

    public boolean deleteFront() {
        return deque.pollFirst() != null;
    }

    public boolean deleteLast() {
        return deque.pollLast() != null;
    }

    public int getFront() {
        Integer first = deque.peekFirst();
        if (first == null) first = -1;
        return first;
    }

    public int getRear() {
        Integer last = deque.peekLast();
        if (last == null) last = -1;
        return last;
    }

    public boolean isEmpty() {
        return deque.isEmpty();
    }

    public boolean isFull() {
        return deque.isFull();
    }
}
